package com.example.webapp.controler;

import com.example.webapp.bean.QuestionBank;
import com.example.webapp.bean.User;
import com.example.webapp.service.QuestionService;
import com.example.webapp.service.StudentExamService;
import com.example.webapp.service.UserService;
import org.aspectj.weaver.patterns.TypePatternQuestions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@Controller
public class UploadControler {
    @Autowired
    private QuestionService questionService;

    @CrossOrigin
    @PostMapping("/upload")
    @ResponseBody
    public String recvFile(@RequestParam("file") MultipartFile file,@RequestParam("answer")String answer) throws IOException {
        byte[] QuestionPic=file.getBytes();
        QuestionBank NewQuestion=new QuestionBank();
        NewQuestion.setQuestion_file(QuestionPic);
        NewQuestion.setScore(5);


        NewQuestion.setQuestion_answer(answer);

        questionService.createQuestion(NewQuestion);
        return "success";
    }
}